package com.sskj.login.router.provider;

import android.content.Context;
import android.util.Log;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.lib.BaseHttpConfig;
import com.sskj.lib.base.IPresenter;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.router.provider.SendSmsProvider;

@Route(path = "/login/service/sendSms")
public class SendSmsProviderImpl implements SendSmsProvider {

    /**
     * type=10 表示注册
     *
     * @param iPresenter
     * @param mobile
     * @param area_code
     * @param type
     * @param onSend
     */
    @Override
    public void send(IPresenter iPresenter, String mobile, String area_code, String type, OnSend onSend) {
        OkGo.<HttpData>post(BaseHttpConfig.BASE_URL + "/api/user/sendSms")
                .params("phone", mobile)
                .params("area_code", area_code.replace("+", ""))
                .params("from", "10".equals(type) ? "register" : null)
                .execute(new JsonCallBack<HttpData>(iPresenter) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        onSend.onSuccess();
                    }

                    @Override
                    public void onError(Response<HttpData> response) {
                        onSend.onFail();
                        super.onError(response);
                    }
                });
    }

    @Override
    public void init(Context context) {

    }
}
